
#include <termios.h>
#include <unistd.h>

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char *argv[])
{
	if(argc != 2)
	{
		printf("argument error.\n");
		exit(1);
	}

	//===============================================
	// password input
	if(isatty(STDIN_FILENO) == 0)
	{
		printf("standard input is not a terminal.\n");
		exit(1);
	}

	struct termios term;
	if(tcgetattr(STDIN_FILENO, &term) < 0)
	{
		perror("tcgetattr function error");
		exit(1);
	}

	term.c_lflag = term.c_lflag & (~ECHO);
	if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0)
	{
		perror("tcsetattr function error");
		exit(1);
	}
	
	printf("please input your password:");

	char pwd[20] = {0};
	scanf("%s", pwd);

	printf("\nyour password you just input is %s.\n", pwd);


	term.c_lflag = term.c_lflag | ECHO;
	if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) < 0)
	{
		perror("tcsetattr function error");
		exit(1);
	}

	//====================================================
	
	return 0;
}
